<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    class Animal {
      constructor(name) {
        this.name = name;
      }
      speak() {
        console.log(`${this.name} makes a noise.`);
      }
    }

    class Dog extends Animal {
      constructor(name) {
        //获取父类需要super()函数调用
        super(name);
      }

      speak() {
        console.log(`${this.name} barks.`);
      }
    }

    let dog = new Dog('Rex');
    dog.speak(); // 输出 'Rex barks
  </script>
</body>

</html>